package com.java.component;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class BeanComponent implements BeanNameAware, BeanPostProcessor {

    @Override
    public void setBeanName(String s) {
        System.out.println("执行通知 BeanName 【" + s + "】");
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean,String beanName){
        System.out.println("do postProcessBeforeInitialization 初始化前置方法！【" + beanName + "】");
        return bean;
    }

    private void myInit(){
        System.out.println("do xml方式初始化");
    }

    @PostConstruct
    private void doPostConstruct(){
        System.out.println("do 注解方式初始化");
    }

    @Override
    public Object postProcessAfterInitialization(Object bean,String beanName){
        System.out.println("do postProcessAfterInitialization 初始化后置方法！【" + beanName + "】");
        return bean;
    }

    public void sayHi(){
        System.out.println("do sayHi()");
    }

    @PreDestroy
    public void doPreDestroy(){
        System.out.println("do 注解方式销毁1");
    }

    public void close(){
        System.out.println("do xml方法销毁");
    }

}
